package com.mall.server.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.commons.exceotion.BusinessException;
import com.mall.commons.exceotion.ErrorResult;
import com.mall.commons.utils.PageUtils;
import com.mall.dubbo.api.ReturnReasonApi;
import com.tanhua.model.domain.OmsOrderReturnReason;
import com.tanhua.model.vo.PageVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class ReturnReasonService {

    @DubboReference
    private ReturnReasonApi returnReasonApi;

    /**
     * 分页查询退货原因分页查询退货原因
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageVo listReturnReason(Integer pageNum, Integer pageSize) {
        Page page = returnReasonApi.listReturnReason(pageNum, pageSize);
        if (page == null) {
            throw new BusinessException(ErrorResult.emptyError());

        }
        PageVo pageDto = PageUtils.getPageVo(page);
        return pageDto;
    }

    //修改退货原因启用状态
    public void updateStatus(Integer status, Integer[] ids) {
        boolean exits = returnReasonApi.updateStatus(status, ids);
        if (!exits) {
            throw new BusinessException(ErrorResult.emptyError());

        }
    }

    //修改退货原因
    public void updateById(Integer id, OmsOrderReturnReason reason) {
        boolean exits = returnReasonApi.updateById(id, reason);
        if (!exits) {
            throw new BusinessException(ErrorResult.emptyError());

        }
    }

    //获取单个退货原因详情信息
    public OmsOrderReturnReason getById(Integer id) {
        OmsOrderReturnReason reason = returnReasonApi.getById(id);
        if (reason == null) {
            throw new BusinessException(ErrorResult.emptyError());

        }
        return reason;
    }

    //批量删除退货原因
    public void deletes(Integer[] ids) {
        boolean exits = returnReasonApi.deletes(ids);
        if (!exits) {
            throw new BusinessException(ErrorResult.emptyError());

        }
    }

    //添加退货原因
    public void create(OmsOrderReturnReason reason) {
        boolean exits = returnReasonApi.create(reason);
        if (!exits) {
            throw new BusinessException(ErrorResult.emptyError());

        }
    }
}
